{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Took 133.387864 second\n"
     ]
    }
   ],
   "source": [
    "#所有上市公司的五张财务表，2015-2020q2期间每个季度的所有财务数据\n",
    "import pandas as pd\n",
    "import time\n",
    "#现在没有规定退市的\n",
    "#上证指数成分股\n",
    "def fun():\n",
    "    start_time = time.time()\n",
    "    li1=get_index_stocks('000001.XSHG')\n",
    "    #深圳指数成分股\n",
    "    li2=get_index_stocks('399106.XSHE')\n",
    "    list3=li1+li2\n",
    "    ret=[]\n",
    "    for s in range (1,7):\n",
    "        year=2014+s\n",
    "        for i in range(1,5):\n",
    "            date=str(year)+'q'+str(i)\n",
    "            q = query(\n",
    "                income,\n",
    "                valuation,\n",
    "                balance,\n",
    "                indicator,          \n",
    "                cash_flow\n",
    "            ).filter(\n",
    "              valuation.code.in_(list3)\n",
    "            )\n",
    "\n",
    "            ret.append(get_fundamentals(q, statDate=date))\n",
    "            df =pd.concat(ret)\n",
    "    #df\n",
    "    df.to_csv('all.csv')\n",
    "    end_time = time.time()\n",
    "    print('Took %f second' % (end_time - start_time))\n",
    "fun()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "MarkDown菜单",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
